import adjacencyList.Node;

import java.util.ArrayList;

public class Solution133 {
    Node[] visited = new Node[100];

    public Node cloneGraph(Node node) {
        if (node == null) {
            return null;
        }
        if (visited[node.val - 1] != null) {
            return visited[node.val - 1];
        }
        ArrayList<Node> copyList = new ArrayList<>();
        Node copy = new Node(node.val, copyList);
        visited[node.val - 1] = copy;
        for (Node neighbor : node.neighbors) {
            copyList.add(cloneGraph(neighbor));
        }
        return copy;
    }
}
